/*************************************************************
 * 
 * CopyRight(c)2007, http://www.moorwind.com/
 * email:ezhung@gmail.com
 * for free, but a email permission would be nice
 * 
 ************************************************************/
package kono.utils
{
	import kono.utils.collections.List;
	
	//链表队列，  linked list queue
	public class LinkedQueue
	{
		private var queue:List;
		
		public function LinkedQueue()
		{
			queue = new List();
		}
		
		public function get size():uint
		{
			return queue.size;
		}
		
		//增加数据到队列中， add the given item into the queue
		public function enqueue(data:*):void
		{
			queue.append(data);
		}
		
		//出队， get the first item in the queue and than remove it from the queue
		public function dequeue():*
		{
			if(queue.head)
			{
				var e:* = queue.head.nodeData;
				queue.removeHead();
				return e;
			}
			else return null;
		}
		
		//返回队首元素， get the first item
		public function peek():*
		{
			return queue.head.nodeData;
		}
		
		//队列是否为空， check if the queue is empty
		public function isEmpty():Boolean
		{
			return queue.tail == null;
		}
		
		public function toString():String
		{
			return "[LinkedQueue, size=" + queue.size + "]";
		}
	}
}